<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title>发情揭发</title>
		<link href="css/new_file.css" rel="stylesheet" type="text/css">
		<link href="css/mui.min.css" rel="stylesheet" type="text/css">

		<script src="js/echarts.min.js"></script>
		<script src="js/mui.min.js"></script>
		<script src="js/testActivityName.js"></script>

		<script charset="UTF-8" src="js/config.js"></script>
		<script charset="UTF-8" src="js/core.js"></script>
		<script charset="UTF-8" src="js/cipher-core.js"></script>
		<script charset="UTF-8" src="js/tripledes.js"></script>
		<script charset="UTF-8" src="js/mode-ecb.js"></script>
		<script src="js/jquery-1.8.3.min.js"></script>
		<script type="text/javascript" src="js/zepto.min.js"></script>
		<script type="text/javascript" src="js/spin.min.js"></script>

	</head>

	<body>
		<div class="spin"></div>
		<div class="head-zhjf">
			<img src="images/fanhui@3x.png" class="ryjk-tx" onclick="fanhuizhuan()">
			<p>发情详情</p>
		</div>
		<!-- <div class="div-tj-aa">
			<div class="fatj-div">
				<div id="main" style="height:270px;width: 100%;"></div>
			</div>
		</div> -->
		<div class="div-tj-aa">
			<div class="fatj-div">
				<div id="main1" style="height:270px;width: 100%;"></div>
			</div>
		</div>
		<div class="moban-lb">
			<div class="moban-lb-l" style="width: 42%">
				<div class="ziduan-mb" onclick="beforeDate()">前一天</div>
			</div>
			<div class="moban-lb-r" style="width: 28%;">
				<input type="date" name="date" id="birthday" readonly="readonly" />
			</div>
			<div class="moban-lb-l" style="float: right">
				<div class="ziduan-mb" style="float: right;margin-right: 15px;" onclick="tomorrowDate()">后一天</div>
			</div>
			<div class="clear"></div>
		</div>
		<script>
			function fanhuizhuan() {
				var lu_route=JSON.parse(localStorage.getItem('lu_route'));
				var DetailsType=JSON.parse(localStorage.getItem('DetailsType'));
				if(lu_route=="数据统计"){
					localStorage.setItem('lu_route', JSON.stringify(""));
					var timenow=JSON.parse(localStorage.getItem('timenow'));
//					var result=JSON.parse(localStorage.getItem('result'));
					var map={};
					map.timenow=timenow;
					datastatis(map);
				}else{
					if (DetailsType==11) {
						tjOestrus();
					}else if (DetailsType==12){
						tjMating();
					}else if (DetailsType==13){
						tjPregnancy();
					}else{
						localStorage.setItem('ToChangeIntoNumber', JSON.stringify(0));
						localStorage.setItem('TurnOutNumber', JSON.stringify(0));
						emotionalSuccessRate();
					}
				}
			}
			var OestrusDetailsArr = JSON.parse(localStorage.getItem('OestrusDetailsData'));
/*			var titleData = new Array();
			for (var i = 0 ;i <OestrusDetailsArr.title.length; i ++) {
				titleData.push(parseInt(OestrusDetailsArr.title[i]));
			}*/
			//var myChart = echarts.init(document.getElementById('main'));
			option = {
				title: {
					y: 5,
					text: '爬跨行为统计',
					textStyle: {
						fontSize: 16,
						font: "微软雅黑",
						color: '#333'
					}
				},
				tooltip: {
					trigger: 'axis',
				},
				legend: {
					x: 'left',
					y: 'top',

					padding: [35, 40, 15, 20],
					itemGap: 20,
					data: ['最近24小时', '过去7天每小时平均值']
				},
				calculable: true,
				xAxis: [{
					data: OestrusDetailsArr.title
				}],
				yAxis: [{}],
				series: [{
						name: '最近24小时',
						type: 'line',
						symbol: 'circle',
						color:'#1a57be',
						width : 30,
						data: OestrusDetailsArr.crawlTodayValue
					},
					{
						name: '过去7天每小时平均值',
						type: 'line',
						symbol: 'circle',
						color: '#fe8828',
						width : 30,
						data: OestrusDetailsArr.crawlWeekValue
					}
				]
			};
			var myChart1 = echarts.init(document.getElementById('main1'));
			option1 = {
				title: {
					y: 5,
					text: '活动量异常统计',
					textStyle: {
						fontSize: 16,
						font: "微软雅黑",
						color: '#333'
					}
				},
				tooltip: {
					trigger: 'axis',
				},
				legend: {
					x: 'left',
					y: 'top',

					padding: [35, 40, 15, 20],
					itemGap: 20,
					data: ['最近24小时', '过去7天每小时平均值']
				},
				calculable: true,
				xAxis: [{
					data: OestrusDetailsArr.title
				}],
				yAxis: [{}],
				series: [{
						name: '最近24小时',
						type: 'line',
						symbol: 'circle',
						color : '#1a57be',
						data: OestrusDetailsArr.activityTodayValue
					},
					{
						name: '过去7天每小时平均值',
						type: 'line',
						symbol: 'circle',
						color: '#b684f3',
						data: OestrusDetailsArr.activityWeekValue
					}
				]
			};

			// 为echarts对象加载数据 
			//myChart.setOption(option);
			myChart1.setOption(option1);
			window.onload=initDate();
			function initDate() {
				var paramsNameDate=JSON.parse(localStorage.getItem('paramsNameDate'));
				var Cow_Id=JSON.parse(localStorage.getItem("Cow_Id"));
				$("#birthday").val(paramsNameDate);
			}
			//前一天
			function beforeDate() {
				var dateStr=$("#birthday").val();
				var datedate=toDate(dateStr);
				var BeforeDate=new Date(datedate.getTime() - 24*60*60*1000);
				$("#birthday").val(dateToStr(BeforeDate));
				findDetails();
			}
			//后一天
			function tomorrowDate() {
				var nowdate=new Date();
				var dateStr=$("#birthday").val();
				var datedate=toDate(dateStr);
				if(datedate.getTime() + 24*60*60*1000>=nowdate.getTime()){
					return;
				}else{
					var BeforeDate=new Date(datedate.getTime() + 24*60*60*1000);
					$("#birthday").val(dateToStr(BeforeDate));
					findDetails();
				}
			}
			//当前时间
			function dandate() {
				var date = new Date();
				var seperator1 = "-";
				var year = date.getFullYear();
				var month = date.getMonth() + 1;
				var strDate = date.getDate();
				if (month >= 1 && month <= 9) {
					month = "0" + month;
				}
				if (strDate >= 0 && strDate <= 9) {
					strDate = "0" + strDate;
				}
				var currentdate = year + seperator1 + month + seperator1 + strDate;
				return currentdate;
			}
			//字符串转日期
			function toDate(str) {
				var shuzu=str.split("-");
				var date=new Date(shuzu[0],shuzu[1]-1,shuzu[2]);
				return date;
			}
			//date转字符串
			function dateToStr(date) {
				var seperator1 = "-";
				var year = date.getFullYear();
				var month = date.getMonth() + 1;
				var strDate = date.getDate();
				if (month >= 1 && month <= 9) {
					month = "0" + month;
				}
				if (strDate >= 0 && strDate <= 9) {
					strDate = "0" + strDate;
				}
				var currentdate = year + seperator1 + month + seperator1 + strDate;
				return currentdate;
			}
			//详情查询
			function findDetails() {
				var keys = JSON.parse(localStorage.getItem('key'));
				var map = {};
				map.key = keys;
				map.cowID = JSON.parse(localStorage.getItem('Cow_Id'));
				map.date=$("#birthday").val();
				map.phoneType = "android";
				map.language = "zh";
				var jsonStr = JSON.stringify(map);
				console.log(jsonStr);
				showDialog();
				var ajaxTimeoutTest = $.ajax({
					type: "POST",
					url: url_prefix + "oestrus",
					dataType: 'JSON',
					timeout: 10000,
					data: {
						'request': encryptByDES(jsonStr)
					},
					async:false,
					success: function(data) {
						dismissDialog();
						var str1 = decryptByDESModeEBC(data["result"]); //解密
						var params = str1.replace(/\+/g, " "); //去掉字符串里的+号
						var str2 = UTFTranslate.ReChange(chineseFromUtf8Url(params)); //转utf8
						var datas = JSON.stringify(str2); //转JSON字符串
						var aa = datas.replace(/\\n/g, " "); //去掉换行
						var objs = eval('(' + aa + ')');
						var bb = eval('(' + objs + ')');
						if(bb.head.status == 1) {
							console.log(bb)
							localStorage.setItem('OestrusDetailsData', JSON.stringify(bb.data));
							localStorage.setItem('paramsNameDate', JSON.stringify(map.date));
							window.location = "发情详情.html";
						} else {
							mui.alert(bb.head.info);
						}
					},
					complete: function(XMLHttpRequest, status) { //请求完成后最终执行参数
						dismissDialog();
						if(status == 'timeout') { //超时,status还有success,error等值的情况
							ajaxTimeoutTest.abort();
							mui.alert("网络请求超时...");
						}
					}
				});
			}
		</script>

	</body>

</html>